//
//  LKSportMapModeViewController.m
//  SportDemo
//
//  Created by Lukj on 2017/4/28.
//  Copyright © 2017年 lukj. All rights reserved.
//

#import "LKSportMapModeViewController.h"

@interface LKSportMapModeViewController ()
//  选中地图类型的block
@property (nonatomic, copy) void(^selectBlock)(MapSelectType mapSelectType);
//地图类型按钮集合
@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *mapModeBtns;

@end

@implementation LKSportMapModeViewController

- (instancetype)initWithSelectBlock:(void (^)(MapSelectType))selectBlock
{
    self = [super init];
    if (self) {
        self.selectBlock = selectBlock;
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    //  设置当前的地图类型
    UIButton *btn = self.mapModeBtns[self.mapSelectType];
    btn.selected = YES;
}

#pragma mark - 响应事件
//  点击地图类型
- (IBAction)clickMapModeBtn:(UIButton *)sender {

    for (UIButton *btn in self.mapModeBtns) {
        // 点击地图类型按钮 判断当前状态是否是选中的状态, 如果是没有选中的状态, 执行block
        if (!sender.selected) {
            //  判断是否有block
            if (self.selectBlock) {
                //  执行block
                self.selectBlock(sender.tag);
            }
        }
        //  设置选中 判断点击的地图类型按钮是否等于集合中的按钮一样, 一样选中, 其他设为NO
        btn.selected = (btn == sender) ? YES : NO;
        
    }
}

@end
